package com.example.mall.config;

import com.example.mall.common.JwtInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 功能: JWT拦截器
 * 作者: 沙琪马
 * 日期: 2025/2/23 14:36
 */
@Configuration
public class WebSocketConfiguration implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(jwtInterceptor()) // 配置Jwt的拦截器规则
                .addPathPatterns("/**")  // 拦截所有的请求路径
                .excludePathPatterns("/api/users/login", "/api/users/logout","/api/users/register")
                //排除静态资源
                .excludePathPatterns("/swagger-ui.html","/swagger-resources/**","/webjars/**","/swagger-ui/**","/v3/api-docs/**","/doc.html");
    }

    @Bean
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }

}